print('initializing the output parameters')
from define_output_parameters import *
from define_problem_space_parameters import *
from calculate_domain_size import fdtd_domain
from initialize_fdtd_parameters_and_arrays import dt
number_of_sampled_electric_fields = len(sampled_electric_fields)
number_of_sampled_magnetic_fields = len(sampled_magnetic_fields)
number_of_sampled_voltages = len(sampled_voltages)
number_of_sampled_currents = len(sampled_currents)

# Initialize frequency domain parameters
frequency_domain["frequencies"] = np.arange(
    frequency_domain["start"],
    frequency_domain["end"] + frequency_domain["step"],  # +step to include end point
    frequency_domain["step"]
)
frequency_domain["number_of_frequencies"] = len(frequency_domain["frequencies"])

# Initialize sampled electric field terms
for ind in range(number_of_sampled_electric_fields):
    # Calculate grid indices
    is_val = round((sampled_electric_fields[ind]["x"] - fdtd_domain["min_x"]) / dx) + 1
    js_val = round((sampled_electric_fields[ind]["y"] - fdtd_domain["min_y"]) / dy) + 1
    ks_val = round((sampled_electric_fields[ind]["z"] - fdtd_domain["min_z"]) / dz) + 1
    
    # Store indices
    sampled_electric_fields[ind]["is"] = is_val
    sampled_electric_fields[ind]["js"] = js_val
    sampled_electric_fields[ind]["ks"] = ks_val
    
    # Initialize sampled values and time array
    sampled_electric_fields[ind]["sampled_value"] = np.zeros(number_of_time_steps)
    sampled_electric_fields[ind]["time"] = np.arange(1, number_of_time_steps + 1) * dt

# Initialize sampled magnetic field terms
for ind in range(number_of_sampled_magnetic_fields):
    # Calculate grid indices
    is_val = round((sampled_magnetic_fields[ind]["x"] - fdtd_domain["min_x"]) / dx) + 1
    js_val = round((sampled_magnetic_fields[ind]["y"] - fdtd_domain["min_y"]) / dy) + 1
    ks_val = round((sampled_magnetic_fields[ind]["z"] - fdtd_domain["min_z"]) / dz) + 1
    
    # Store indices
    sampled_magnetic_fields[ind]["is"] = is_val
    sampled_magnetic_fields[ind]["js"] = js_val
    sampled_magnetic_fields[ind]["ks"] = ks_val
    
    # Initialize sampled values and time array
    sampled_magnetic_fields[ind]["sampled_value"] = np.zeros(number_of_time_steps)
    sampled_magnetic_fields[ind]["time"] = np.arange(1, number_of_time_steps + 1) * dt

# # initialize sampled magnetic field terms
# for ind=1:number_of_sampled_magnetic_fields  
#     is = round((sampled_magnetic_fields(ind).x \
#         - fdtd_domain.min_x)/dx)+1
#     js = round((sampled_magnetic_fields(ind).y \
#         - fdtd_domain.min_y)/dy)+1
#     ks = round((sampled_magnetic_fields(ind).z \
#         - fdtd_domain.min_z)/dz)+1
#     sampled_magnetic_fields(ind).is = is
#     sampled_magnetic_fields(ind).js = js
#     sampled_magnetic_fields(ind).ks = ks
#     sampled_magnetic_fields(ind).sampled_value = \
#         zeros(1, number_of_time_steps)
#     sampled_magnetic_fields(ind).time = \
#         ([1:number_of_time_steps]-0.5)*dt
# end

# # initialize sampled voltage terms
# for ind=1:number_of_sampled_voltages  
#     is = round((sampled_voltages(ind).min_x - fdtd_domain.min_x)/dx)+1
#     js = round((sampled_voltages(ind).min_y - fdtd_domain.min_y)/dy)+1
#     ks = round((sampled_voltages(ind).min_z - fdtd_domain.min_z)/dz)+1
#     ie = round((sampled_voltages(ind).max_x - fdtd_domain.min_x)/dx)+1
#     je = round((sampled_voltages(ind).max_y - fdtd_domain.min_y)/dy)+1
#     ke = round((sampled_voltages(ind).max_z - fdtd_domain.min_z)/dz)+1
#     sampled_voltages(ind).is = is
#     sampled_voltages(ind).js = js
#     sampled_voltages(ind).ks = ks
#     sampled_voltages(ind).ie = ie
#     sampled_voltages(ind).je = je
#     sampled_voltages(ind).ke = ke
#     sampled_voltages(ind).sampled_value = \
#                         zeros(1, number_of_time_steps)
# 
#     switch (sampled_voltages(ind).direction(1))
#     case 'x'
#         fi = create_linear_index_list(Ex,is:ie-1,js:je,ks:ke)
#         sampled_voltages(ind).Csvf = -dx/((je-js+1)*(ke-ks+1))
#     case 'y'
#         fi = create_linear_index_list(Ey,is:ie,js:je-1,ks:ke)
#         sampled_voltages(ind).Csvf = -dy/((ke-ks+1)*(ie-is+1))
#     case 'z'
#         fi = create_linear_index_list(Ez,is:ie,js:je,ks:ke-1)
#         sampled_voltages(ind).Csvf = -dz/((ie-is+1)*(je-js+1))
#     end    
#     if strcmp(sampled_voltages(ind).direction(2),'n')
#         sampled_voltages(ind).Csvf =  \
#             -1 * sampled_voltages(ind).Csvf
#     end
#     sampled_voltages(ind).field_indices = fi
#     sampled_voltages(ind).time = ([1:number_of_time_steps])*dt
# end

# # initialize sampled current terms
# for ind=1:number_of_sampled_currents  
#     is = round((sampled_currents(ind).min_x - fdtd_domain.min_x)/dx)+1
#     js = round((sampled_currents(ind).min_y - fdtd_domain.min_y)/dy)+1
#     ks = round((sampled_currents(ind).min_z - fdtd_domain.min_z)/dz)+1
#     ie = round((sampled_currents(ind).max_x - fdtd_domain.min_x)/dx)+1
#     je = round((sampled_currents(ind).max_y - fdtd_domain.min_y)/dy)+1
#     ke = round((sampled_currents(ind).max_z - fdtd_domain.min_z)/dz)+1
#     sampled_currents(ind).is = is
#     sampled_currents(ind).js = js
#     sampled_currents(ind).ks = ks
#     sampled_currents(ind).ie = ie
#     sampled_currents(ind).je = je
#     sampled_currents(ind).ke = ke
#     sampled_currents(ind).sampled_value = \
#                         zeros(1, number_of_time_steps)
#     sampled_currents(ind).time =([1:number_of_time_steps]-0.5)*dt
# end
